package m.jclecai.com.bean;

import android.util.Log;

import java.io.Serializable;
import java.util.List;

import m.jclecai.com.contents.LotteryType;

/**
 * Created by ZD on 2017/4/24.
 */

public class BuyParamBean implements Serializable {
    private int redCount;
    private int blueCount;
    private int gid = 19;
    private String codes = "";

    public BuyParamBean(int redCount, int blueCount, List<List<String>> codes) {
        this.redCount = redCount;
        this.blueCount = blueCount;
        this.codes = formatCodes(codes);
    }


    private String formatCodes(List<List<String>> datas) {
        String str = "";
        for (int i = 0; i < datas.size(); i++) {
            List<String> strs = datas.get(i);
            for (int j = 0; j < strs.size(); j++) {
                //红球拼接-红球的个数
                if (redCount > j) {
                    str += strs.get(j).trim();
                    if (redCount - 1 > j)
                        str += ",";
                    else
                        str += "|";
                } else {
                    //蓝球拼接
                    str += strs.get(j).trim();
                    //如果只有一个蓝球不需要，结尾
                    if (j < strs.size() - 1)
                        str += ",";
                }
            }

            if (str.endsWith("|")) {
                str += LotteryType.DEFAULT;
            } else {
                str += ":" + LotteryType.DEFAULT;
            }
            if (i < datas.size() - 1)
                str += ";";
        }
        Log.e("BuyParamBean format", str);
        return str;
    }

    public int getGid() {
        return gid;
    }

    public void setGid(int gid) {
        this.gid = gid;
    }

    public String getCodes() {
        return codes;
    }

    public void setCodes(String codes) {
        this.codes = codes;
    }

    @Override
    public String toString() {
        String params = "gid=" + gid +
                "redCount=" + redCount +
                "blueCount=" + blueCount +
                "&codes=" + codes;
        return params;
    }
}
